﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using BLL;
using Model;

namespace AcceptServer
{
    public class OperateDataBase
    {

        readonly BTrade _bTrade = new BTrade();
        readonly BTaxiGpsHistory _bTaxiGpsHistory = new BTaxiGpsHistory();
        readonly BComplaint _bComplaint = new BComplaint();
        readonly BTaxiADInfo _bTaxiAd = new BTaxiADInfo();
        readonly BDriver _bDriver = new BDriver();
        readonly BTaxiArea _bTaxiArea = new BTaxiArea();
        readonly BPhoneuser _bPhoneuser = new BPhoneuser();
        private readonly BTaxiWarming _bTaxiWarming = new BTaxiWarming();
        private readonly BTaxi _bTaxi = new BTaxi();
        private readonly BCallRecords _bCallRecords = new BCallRecords();
        private readonly BServerConfig _bServerConfig = new BServerConfig();
        private readonly BAdMachine _bAdMachine = new BAdMachine();
        private readonly BPrivateCar _bPrivateCar = new BPrivateCar();
        private readonly BPhonePlatform _bPhonePlatform = new BPhonePlatform();
        private readonly BAccreditation _bAccreditation = new BAccreditation();
        private readonly BCardCheckHistory _bCardCheckHistory = new BCardCheckHistory();
        //private readonly BDestination _bDestination = new BDestination();
        private readonly BTaxiCDMA _bTaxiCdma = new BTaxiCDMA();


        /// <summary>
        /// Add Trade successful  Info
        /// </summary>
        /// <param name="tradeInfo"></param>
        public void AddTradeInfo(TradeInfo tradeInfo)
        {
            _bTrade.Add(tradeInfo);
        }

        public void AddTaxiGpsHistoryInfo(TaxiGpsHistoryInfo taxiGpsHistoryInfo)
        {
            _bTaxiGpsHistory.Add(taxiGpsHistoryInfo);
        }

        public int AddListTaxiGpsHistory(string sql)
        {
            return  _bTaxiGpsHistory.AddList(sql);
        }

        public int GetRecordCountOfUserInThisMonth(string phoneNumber, int complaintObject)
        {
            return _bComplaint.GetRecordCountOfUserInThisMonth(phoneNumber, complaintObject);
        }


        public DataSet TaxiGetAdSeting(string phoneNumber)
        {
            ArrayList al = _bDriver.ExistsDriverPhoneNumber(phoneNumber);

            if (al != null)
            {
                string taxiId = al[0].ToString();
                return _bTaxiAd.GetList("TaxiId=" + taxiId);
            }
            return null;
        }

        public DataSet TaxiGetAreaSeting(string phoneNumber)
        {
            ArrayList al = _bDriver.ExistsDriverPhoneNumber(phoneNumber);

            if (al != null)
            {
                string taxiId = al[0].ToString();
                return _bTaxiArea.GetList("TaxiId=" + taxiId);
            }
            return null;
        }



        public bool PhoneuserExists(string phonenumber)
        {
            return _bPhoneuser.Exists(phonenumber);
        }

        public bool PhoneuserAdd(Model.PhoneUserInfo model)
        {
            return _bPhoneuser.Add(model);
        }

        public bool  PhoneuserUpdate(Model.PhoneUserInfo model)
        {
            return _bPhoneuser.Update(model);
        }

        public bool PhoneuserUpdateByNum(string phoneNumber, int type, string lastLonginTime)
        {
            return _bPhoneuser.UpdateByPhoneNumber(phoneNumber, type, lastLonginTime);
        }

        public bool PhoneuserUpdateRecommender(string phoneNumber, string recommender)
        {
            return _bPhoneuser.UpdateRecommender(phoneNumber, recommender);
        }

        public bool PhoneuserUpdateByIMEI(string imei, string version, string lastLonginTime)
        {
            return _bPhoneuser.UpdateByIMEI(imei, version, lastLonginTime);
        }

        public Model.PhoneUserInfo PhoneuserGetModelByPhoneNumber(string phoneNumber)
        {
            return _bPhoneuser.GetModelByPhoneNumber(phoneNumber);
        }

        /// <summary>
        /// 更新出租车评分  
        /// </summary>
        /// <param name="starLevel">评分</param>
        /// <param name="phoneNumber">手机号</param>
        /// <returns></returns>
        public bool TaxiUpdateStarLevel(int starLevel, string phoneNumber)
        {
            return _bDriver.UpdateStarLevel(starLevel, phoneNumber);
        }

        public bool TaxiWarmingAdd(TaxiWarmingInfo model)
        {
            return _bTaxiWarming.Add(model);
        }

        public string[] GetWarmingParmsByPhoneNumber(string phoneNumber)
        {
            return _bTaxi.GetParametersByPhoneNum(phoneNumber);
        }

        public bool CallRecordAdd(CallRecordsInfo model)
        {
            return _bCallRecords.Add(model);
        }

        public ServerConfigInfo ServerConfigGetModelById(int id)
        {
            return _bServerConfig.GetModel(id);
        }


        public bool PhoneUserImeiExit(string imei)
        {
            return _bPhoneuser.IMEIExists(imei);
        }

       public string GetTaxiNoByPhoneNumber(string phoneNumber)
       {
           return _bDriver.GetTaxiNoByPhoneNumber(phoneNumber);
       }

       /// <summary>
       /// 获得黑名单列表
       /// </summary>
       /// <returns></returns>
       public List<string> GetBlackListOfPasseager()
       {
           return _bComplaint.GetBlackListOfPasseager();
       }

        public string GetAdMachineAdUrlByNumber(string number)
        {
            return _bAdMachine.GetAdUrlByNumber(number);
        }


        public ArrayList ExistsDriverPhoneNumber(string phoneNum)
        {
            return _bDriver.ExistsDriverPhoneNumber(phoneNum);
        }

         
        public bool UpdateIMEIByPhoneNumber(string phoneNumber,string IMEI)
        {
            return _bDriver.UpdateIMEIByPhoneNumber(phoneNumber, IMEI);
        }

        public TaxiInfo DriverGetModel(int taxiId)
        {
            return _bTaxi.GetModel(taxiId);
        }

        public int GetDriverStar(string phoneNum)
        {
            return _bDriver.GetDriverStar(phoneNum);
        }



        public bool PrivateCarExistsPhoneNum(string phoneNumber)
        {
            return _bPrivateCar.Exists(phoneNumber);
        }

        public bool PrivateCarAdd(Model.PrivateCarInfo model)
        {
            return _bPrivateCar.Add(model);
        }

        public bool PrivateCarUpdateByPhoneNum(string phoneNumber, DateTime lastLoginTime)
        {
            return _bPrivateCar.Update(phoneNumber,  lastLoginTime);
        }

        public bool PrivateCarDeleteByPhoneNum(string phoneNumber)
        {
            return _bPrivateCar.DeleteByPhoneNumber(phoneNumber);
        }

        public bool PrivateCarUpdateSignature(string phoneNumber, string signature)
        {
            return _bPrivateCar.UpdateSignatureByPhoneNumber(phoneNumber, signature);
        }

        public bool TaxiUpdateSignature(string phoneNumber, string signature)
        {
            return _bDriver.UpdateSignatureByPhoneNumber(phoneNumber, signature);
        }

        public bool PrivateCarUpdateInfoByPhoneNumber(Model.PrivateCarInfo model)
        {
            return _bPrivateCar.UpdateCarInfoByPhoneNumber(model);
        }


        public Model.PrivateCarInfo PrivateCarGetModel(string phoneNum)
        {
            return _bPrivateCar.GetModel(phoneNum);
        }

        #region  PhonePlatform

        public bool PhonePlatformExistsNumber(string phonenumber)
        {
            return _bPhonePlatform.ExistsNumber(phonenumber);
        }

        public bool PhonePlatformAdd(Model.PhonePlatformInfo model)
        {
            return _bPhonePlatform.Add(model);
        }

        public bool PhonePlatformUpdateAfterLogin(string number, string version)
        {
            return _bPhonePlatform.UpdateAfterLogin(number, version);
        }

        public bool PhonePlatformUpdateArea(string number, string area)
        {
            return _bPhonePlatform.UpdateArea(number, area);
        }
        #endregion


        #region Accreditation
        public int AccreditationCheckIdentityInfo(string id, string password)
        {
            return _bAccreditation.CheckIdentityInfo(id, password);
        }

        public Model.DriverIdentityInfo AccreditationGetModel(string id)
        {
            return _bAccreditation.GetModel(id);
        }

        public bool AccreditationChangePassword(string driverId, string oldPassword, string newPassworld)
        {
            return _bAccreditation.ChangePassword(driverId, oldPassword, newPassworld);
        }

        public Model.DriverIdentityInfo AccreditationCheckIdentityWithReturn(
            string cardid, string password)
        {
            return _bAccreditation.CheckIdentityWithReturn(cardid, password);
        }

        public bool AccreditationExistPhoneNumber(string phoneNumber)
        {
            return _bAccreditation.ExistPhoneNumber(phoneNumber);
        }

        public Model.DriverIdentityInfo AccreditationGetModelByPhoneNumber(string phoneNum)
        {
            return _bAccreditation.GetModelByPhoneNumber(phoneNum);
        }

        #endregion

        public bool CardCheckHistoryAdd(Model.CardCheckHistoryInfo model)
        {
            return _bCardCheckHistory.Add(model);
        }


        public Model.TaxiCdmaInfo CdmaTaxiGetModelByDeviceNumber(string deviceNumber)
        {            
            return _bTaxiCdma.GetModelByDeviceNumber(deviceNumber);
        }

        public DataSet CdmaTaxiGetList()
        {
            return _bTaxiCdma.GetList(""); 
        }

    }
}
